package com.orange.wwwapi.controller.product;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.orange.core.pojo.PageReqDto;
import com.orange.core.pojo.R;
import com.orange.core.pojo.entity.product.CreditProduct;
import com.orange.core.pojo.req.product.CreditProductPageReq;
import com.orange.core.service.product.CreditProductService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

/**
 * 积分商品
 */
@RequiredArgsConstructor
@RestController
@RequestMapping("/creditProduct")
public class CreditProductController {

    private final CreditProductService creditProductService;

    /**
     * 列表
     */
    @PostMapping("/page")
    public R<Page<CreditProduct>> page(@RequestBody PageReqDto<CreditProductPageReq> req) {
        if (req.getCondition() == null) {
            req.setCondition(new CreditProductPageReq());
        }
        req.getCondition().setShelf(1);
        return R.ok(creditProductService.page(req));
    }

    /**
     * 详情
     */
    @GetMapping("/{id}")
    public R<CreditProduct> info(@PathVariable("id") int id) {
        return R.ok(creditProductService.info(id));
    }
}
